﻿@{
    ViewBag.Title = "Index";
}
<div class="layui-form-item">
    <div class="layui-inline">
        <div class="layui-input-inline">
            <input type="text" id="Code" placeholder="园区名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <a class="layui-btn" id="btnSearch">搜索</a>
    </div>
</div>
<table id="table" class="layui-table" lay-filter="table"></table>
<script type="text/html" id="rowbar">
    <a class="layui-btn layui-btn-xs" lay-event="show3d">三维漫游</a>
</script>
<script>
    layui.use(['table', 'layer'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        //查询
        function getWhere() {
            var where = { Code: $("#Code").val() };
            return where;
        }
        layui.tableReload = function () {
            table.reload("table", {
                where: getWhere(),
                page: { curr: 1 }
            });
        }
        $("#btnSearch").click(function () {
            layui.tableReload();
        })
        // 渲染表格
        table.render({
            id: "table",
            elem: '#table',
            method: "post",
            url: 'List',
            cellMinWidth: 80,
            cols: [
                [
                    { type: 'checkbox' },
                    { field: 'Code', title: '园区名称' },
                    { field: 'DeptName', title: '所属公司' },
                    { field: 'Area', title: '园区面积' },
                    { field: 'Address', title: '园区地址' },
                    { field: 'Longitude', title: '经度' },
                    { field: 'Latitude', title: '纬度' },
                    { field: 'CreateDate', title: '创建日期' },
                    { fixed: 'right', title: '操作', align: 'center', toolbar: '#rowbar' }
                ]
            ],
            done: function (res, curr, count) { //res 即为原始返回的数据
                //console.log(res);
            },
            loading: true,
            event: true,
            page: { limit: 20 }
        });
        
        //监听工具条
        table.on('tool(table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'show3d') {
                if (data.Url3D) {
                    layer.open({
                        type: 2,
                        title: '三维漫游',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '/Resource/Show3D/ShowWalk?id=' + data.ID
                    });
                }
                else
                    layer.msg("尚未配置3D模型链接");
            }
        });
    });
</script>
